cmake_minimum_required(VERSION 3.15.2)

project(eazyrpc CXX C)

option(GLIBC_COMPATIBILITY "Enable compatibility with older glibc libraries." ON)
message(STATUS "GLIBC_COMPATIBILITY is ${GLIBC_COMPATIBILITY}")

# set CMAKE_BUILD_TYPE
if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RELEASE)
endif()

string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")

# set CMAKE_BUILD_TARGET_ARCH
# use `lscpu | grep 'Architecture' | awk '{print $2}'` only support system which language is en_US.UTF-8
execute_process(COMMAND bash "-c" "uname -m"
        OUTPUT_VARIABLE
        CMAKE_BUILD_TARGET_ARCH
        OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Build target arch is ${CMAKE_BUILD_TARGET_ARCH}")


# Set dirs
set(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
#set(GENSRC_DIR "${BASE_DIR}/../gensrc/build/")
set(SRC_DIR "${BASE_DIR}/src/")
set(OUTPUT_DIR "${BASE_DIR}/output")


# Check gcc
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.3.0")
        message(FATAL_ERROR "Need GCC version at least 7.3.0")
    endif()
    message(STATUS "GCC version is greater than 7.3.0, disable -Werror. Be careful with compile warnings.")
elseif (NOT APPLE)
    message(FATAL_ERROR "Compiler should be GNU")
endif()

include_directories( /usr/include/boost/ )
link_libraries(/usr/local/lib/)

set( Server_SOURCES
        src/SQLServer.cpp
        src/SQLService_types.cpp
        src/SQLService_constants.cpp
        src/SQLService.cpp)

set( Client_SOURCES
        src/SQLService_types.cpp
        src/SQLService_constants.cpp
        src/SQLService.cpp
        src/RPCCLient.cpp)


add_executable(RPCServer ${Server_SOURCES})

target_link_libraries( RPCServer libthrift.a libthriftnb.a )


add_executable(RPCClient ${Client_SOURCES})
target_link_libraries( RPCClient libthrift.a libthriftnb.a )